/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.oimwrapper.testers;

import Thor.API.Operations.tcFormDefinitionOperationsIntf;
import Thor.API.Operations.tcFormInstanceOperationsIntf;
import com.thortech.util.logging.Logger;
import org.junit.Test;
import org.oimwrapper.connectors.OIMRemoteClientBase;


/**
 * 1. generate a public key with keytool
 * keytool -genkey -keystore .xlkeystore -alias fredslaptop -storepass xellerate -keypass abcd1234
 * -dname "CN=Fred Forester, OU=Development, O=FredsDevelopment, L=Rehoboth, S=DE, C=US"
 * 2. export a public key
 * keytool -export -alias fredslaptop -keystore .xlkeystore -file fredslaptop_certfile.cer
 * 3. import the key into server config .xlkeystore
 * keytool -import -alias fredslaptop -file fredslaptop_certfile.cer -keystore .xlkeystore
 * 4. modify the client xlconfig.xml after the discovery settings
 * <Security>
                <XLPKIProvider>
                        <KeyStore>
                                <Location>.xlkeystore</Location>
                                <Password encrypted="false">xellerate</Password>
                                <Type>JKS</Type>
                                <Provider>sun.security.provider.Sun</Provider>
                        </KeyStore>
                        <Keys>
                                <PrivateKey>
                                        <Alias>fredslaptop</Alias>
                                        <Password encrypted="false">abcd1234</Password>
                                </PrivateKey>
                        </Keys>
                        <SignatureAlgorithm>SHA1withDSA</SignatureAlgorithm>
                        <SignatureProvider>sun.security.provider.Sun</SignatureProvider>
                        <VerifySigner>true</VerifySigner>
                </XLPKIProvider>
    </Security>
 * 5. restart the server
 * 6. create a user in oim with admin privs called armsys
 * 7. run this test.
 */
public class ClientSignatureTester {

    private static tcFormDefinitionOperationsIntf formDefOps;
    private static tcFormInstanceOperationsIntf formInstanceOps;
    
    private static final Logger logger = Logger.getLogger(ClientSignatureTester.class.getName());

    @Test
    public void mainTest()
    {
        logger.debug("Starting ");
        OIMRemoteClientBase tester = null;
        logger.debug("Logging In ");
        try {
            tester = new OIMRemoteClientBase();
            System.setProperty("XL.HomeDir", TesterConfig.XL_HomeDir);
            tester.setConnectionInfo(TesterConfig.XL_USERID);
            tester.connect();
        } catch (Exception ex) {
            logger.error("Exception",ex);
            return;
        }

        logger.debug("Logged In! ");

        try {
            formDefOps = (tcFormDefinitionOperationsIntf)tester.getUtils().getUtility(Thor.API.Operations.tcFormDefinitionOperationsIntf.class);
            formDefOps.close();
        } catch (Exception ex) {
            logger.error("Exception",ex);
        }
        try {
            formInstanceOps = (tcFormInstanceOperationsIntf)tester.getUtils().getUtility(Thor.API.Operations.tcFormInstanceOperationsIntf.class);
            formInstanceOps.close();
        } catch (Exception ex) {
            logger.error("Exception",ex);
        }

        logger.debug("Success");
        tester.disconnect();
        //System.exit(0);


    }
}
